using Prologis.Logging;
using System.IO;



namespace Prologis.ShifterNT.Datasink
{


    public class FileDataSink : IDataSink
    {

        Logger logger = new Logger("Prologis.Shifter");



        /// <summary>
        /// 
        /// </summary>
        /// 
        bool active = false;
        public bool Active
        {
            get { return active; }
            set
            {
                if (active != value)
                {
                    active = value;

                    if (active)
                    {


                    }
                    else
                    {

                    }
                }
            }
        }



        public string FilePath { get; set; }



        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// 
        public void Take(FieldList data)
        {

            if (false == File.Exists(this.FilePath))
            {
                using (FileStream s = File.Create(this.FilePath))
                {
                    s.Flush();
                    s.Close();
                }
            }
                        
            string newLine = data.ToString();

            using (StreamWriter w = File.AppendText(this.FilePath))
            {
                w.WriteLine(newLine);
                // Update the underlying file.
                w.Flush();
                // Close the writer and underlying file.
                w.Close();
            }

        }


    }

}
